package scau.erps.view.system.teacher;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.DefaultTableCellRenderer;

import scau.erps.app.Erps;
import scau.erps.entity.SystemOrder;
import scau.erps.service.SystemOrderService;
import scau.erps.service.impl.SystemOrderServiceImpl;
import scau.erps.util.CalculateQuarter;

/**
 * 系统订单面板模板
 * @author DCJ
 *
 */
public abstract class SystemOrderPanelTemplate extends JPanel implements ActionListener {
	private static final long serialVersionUID = 1L;
	protected JPanel contentPanel,actionPanel;
	protected JComboBox<String> yearCombo,productCombo,marketCombo;
	protected JButton filterBtn,deleteBtn,refreshBtn,biddingBtn,endBiddingBtn;
	protected JTable table;
	protected JScrollPane dataPanel;
	protected DefaultTableCellRenderer render;
	protected OrderListModel dataModel;
	public SystemOrderPanelTemplate(){
		yearCombo = new JComboBox<String>(new String[]{"选择年份","Y1","Y2","Y3","Y4","Y5","Y6","Y7","Y8"});
		productCombo = new JComboBox<String>(new String[]{"选择产品","Beryl","Crystal","Ruby","Sapphire"});
		marketCombo = new JComboBox<String>(new String[]{"选择市场","本地","区域","国内","亚洲","国际"});		
		filterBtn = new JButton("筛选");
		deleteBtn = new JButton("批量删除订单");
		refreshBtn = new JButton("刷新");
		biddingBtn = new JButton("竞价");
		endBiddingBtn = new JButton("结束竞价");
		biddingBtn.addActionListener(this);	
		filterBtn.addActionListener(this);
		deleteBtn.addActionListener(this);
		refreshBtn.addActionListener(this);
		endBiddingBtn.addActionListener(this);
		actionPanel = new JPanel(); //顶部交互操作面板
		actionPanel.add(yearCombo);
		actionPanel.add(productCombo);
		actionPanel.add(marketCombo);
		actionPanel.add(filterBtn);
		actionPanel.add(deleteBtn);	
		actionPanel.add(refreshBtn);
		actionPanel.add(biddingBtn);
		actionPanel.add(endBiddingBtn);
		table = new JTable();
		table.setPreferredScrollableViewportSize(new Dimension(900, 450));
		table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		dataPanel = new JScrollPane(table);
		dataPanel.setViewportView(table);
		render = new DefaultTableCellRenderer();   
		render.setHorizontalAlignment(JLabel.CENTER);   
		table.setDefaultRenderer(Object.class,render);
		contentPanel = new JPanel();
  		contentPanel.setLayout(new BorderLayout());
		contentPanel.add(actionPanel,BorderLayout.NORTH);
		contentPanel.add(dataPanel,BorderLayout.CENTER);
		this.add(contentPanel);
		this.setVisible(true);
		this.dataModel = getOrderListModel();
		this.table.setModel(dataModel);
	}
	public OrderListModel getOrderListModel(){
		SystemOrderService systemOrderService = Erps.getIocInstance().get(SystemOrderServiceImpl.class);
		
		List<SystemOrder> list = null;
		if (Erps.getCurrentTeam()==null) {
			list = systemOrderService.getAllSystemOrders();
		}else{
			String year = CalculateQuarter.getCurrentYear(Erps.getSand().getTime());
			list = systemOrderService.getSystemOrders(year, null, null);
		}				
		dataModel = new OrderListModel(list);
		return dataModel;
				
	}
	
}	



